﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Pages_HomePage_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        lblWarning.Visible = false;
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        ManagerBUS m = new ManagerBUS();
        StudentBUS st = new StudentBUS();
        StaffBUS staff = new StaffBUS();
        string user = txtUserName.Text;
        string pass = txtPassword.Text;
        DataSet stDs = st.studentLogin(user, pass);
        DataSet mDs = m.managerLogin(user, pass);
        DataSet staffDs = staff.staffLogin(user, pass);
        if (mDs.Tables[0].Rows.Count > 0)
        {
            Session["Id"] = mDs.Tables[0].Rows[0]["managerId"].ToString();
            Session["UserName"] = mDs.Tables[0].Rows[0]["userName"].ToString();
            Session["Role"] = "Manager";
            Response.Redirect("~/Pages/ManagerPages/ManagerHome.aspx");
        }
        else if (staffDs.Tables[0].Rows.Count > 0)
        {
            Session["Id"] = staffDs.Tables[0].Rows[0]["staffId"].ToString();
            Session["UserName"] = staffDs.Tables[0].Rows[0]["userName"].ToString();
            Session["Role"] = "Staff";
            Response.Redirect("~/Pages/StaffPages/StaffHome.aspx");
        }
        else if (stDs.Tables[0].Rows.Count > 0)
        {
            Session["Id"] = stDs.Tables[0].Rows[0]["studentId"].ToString();
            Session["UserName"] = stDs.Tables[0].Rows[0]["userName"].ToString();
            Session["Role"] = "Student";
            Response.Redirect("~/Pages/StudentPages/StudentsHome.aspx");
        }
        else
        {
            lblWarning.Visible = true;
        }
    }
}